<template>
	<!-- <uni-transition mode-class="fade" :duration="200" :show="true"> -->
		<view>
			<view class="tab-content">
				<slot />
			</view>
			<view class="tabbar">
				<view class="navigator">
					<view ref='warpper' class="warpper">
						<view ref="navItem" class="navigator-item" v-for="(item,index) in tabBar.list"
							:key="item.pagePath" @click="switchTab(item,index)" :data-index='index'>
							<img :src="item.iconPath" class="icon" v-if="selectedIndex !== index">
							<img :src="item.selectedIconPath" class="icon" v-else>
							<text :class="['item-text',{'text-active':selectedIndex === index}]">{{item.text}}</text>
							<text v-show="item.text=='购物车' && cartCount>0" class="gwc">{{cartCount}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	<!-- </uni-transition> -->
 
</template>

<script>
	export default {
		data() {
			return {
				cartCount:0,
				selectedIndex: uni.getStorageSync('selectedIndex') || 0, // 标记
				tabBar: {
					list: [{
							"pagePath": "pages/index/index",
							"iconPath": "../static/index1.png",
							"selectedIconPath": "../static/index.png",
							"text": "首页"
						},
						{
							"pagePath": "pages/shop/classify",
							"iconPath": "../static/shop.png",
							"selectedIconPath": "../static/shop1.png",
							"text": "分类"
						},
						{
							"pagePath": "pages/shop/car",
							"iconPath": "../static/car1.png",
							"selectedIconPath": "../static/car.png",
							"text": "购物车"
						},
						{
							"pagePath": "pages/my/my",
							"iconPath": "../static/mine1.png",
							"selectedIconPath": "../static/mine.png",
							"text": "我的"
						}
					]
				},
			}
			
			
		},
		
		
		onLoad() {
			this.aa()
		},
		methods: {
			aa(){
				const pages = getCurrentPages();
				const currentPage = pages[pages.length - 1];
				const pagePath = currentPage.route;
				 
				console.log('当前页面路径为：' + pagePath);
			},
			switchTab(item, index) {
				let url = '/' + item.pagePath
				let pagePath = url
				uni.switchTab({url})
				this.tabBar.list.forEach((v, i) => {
					if (item.pagePath === v.pagePath) {
						uni.setStorageSync('selectedIndex', index);
					}
				})
			},
      /**
       * 购物车列表
       * **/
      getCount(){
        console.log("底部购物车");
        this.$myRequest({
          url: 'api/cart/index',
          method:'GET',
        }).then(res=>{
          console.log(res,"底部数量");
          if(res.data.code==1){
            this.cartCount = res.data.data.num
          }
        })
      },
		},
		
	}
</script>


<style lang="scss">
	.tabbar {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 120rpx;
		z-index: 999;
		background: #F5F5F5;
		border-top: 2rpx solid #eee;
	}
 
	.navigator {
		width: 85%;
		margin: 0 auto;
		padding:20rpx 0 25rpx 0;
		overflow: hidden;
	}
 
	.warpper {
		display: flex;
		justify-content: space-between;
		width: auto;
		transition-timing-function: ease-out;
	}
 
	.navigator-item {
		display: flex;
		align-items: center;
		flex-direction: column;
		width: 80rpx;
		height: 100%;
		position: relative;
	}
 
	.item-text {
		margin-top: 6rpx;
		color: #777E86;
		font-size: 24rpx;
	}
 
	.text-active {
		color: #F57E28 !important;
	}
 
	.icon {
		width: 25px;
		height: 25px;
	}
	.gwc{
    font-size: 24rpx;
    position: absolute;
    background: #f00;
    color: #fff;
    border-radius: 50%;
    padding: 5rpx;
    top: -10rpx;
    right: -5px;
    width: 30rpx;
    height: 30rpx;
    line-height: 30rpx;
    text-align: center;}
</style>

